<?php

//用于写产品的相关替换函数

require_once(dirname(__FILE__).'/../products/iskysoft_products.php');
class IskysoftBuy extends IskysoftProducts {
	var $db;
	function __construct(){
		$this->db = $GLOBALS['db'];
		parent::__construct( $this->db );
	}
	
	
	/**
	 * 产品页面地址
	 * */
	function productUrl( $get ){
		$id = $get["产品ID"];

		$sql = "SELECT `url` FROM `Table_137` where `Field_21669` = '{$id}'";
		$url = $this->db->getOne($sql);
		if(!$url){
			$sql = "SELECT `url` FROM `Table_147` WHERE `Field_21726` = '{$id}'";
			$url = $this->db->getOne( $sql );
		}
		
		return str_replace('/iskysoft.com/httpdocs/', 'http://www.iskysoft.com/', $url);
	}
	/**
	 * 产品价格
	 * */
	function productPrice( $get ){

		$id = $get["产品ID"];
		$sql = "SELECT `won_product_id` FROM `won_product` WHERE id = '{$id}'";
		
		$product_id = $this->db->getOne( $sql );
		if( !$product_id ) return $product_id;
		
		$sql = "SELECT count(*) AS total FROM `license` 
				WHERE `license_id` = 11 AND `website_display` = 1 AND `license_delete` = 0 AND `product_id` = '{$product_id}'";
		$total = $this->db->getOne($sql);
		
		$sql = "SELECT `product_is_year_charge` FROM product WHERE `product_delete` = 0 AND `product_id` = '{$product_id}'";
		$product_year = $this->db->getOne($sql);
		
		$price_start = $del_price_start = '';
		$price_one = array();
		if( $total )
		{
			$price_one = get_price_license($product_id,11);
			$product_price = explode(".",$price_one['curr']);
			
			if($product_year){
				$price_start ='$'.intval($product_price[0]).'.'.$product_price[1].'/Year';
			}else{
				$price_start ='$'.intval($product_price[0]).'.'.$product_price[1];
			}
			
			if($price_one['unique']){
				$del_price_start ='$'.$price_one['old'];
			}	
		}
		
		$paypal_str = '&language=English&currency=USD';
		
		$cart_url = '';
		if( $total ){
			$str_checked = 'checked="checked"';
			
		    if( !empty($price_one['cart_url']) )
		    {
				$str .= '<li show="1"  >
					<input id="s12" name="s1" type="radio" value="'.$price_one['cart_url'].$paypal_str.'"  
					'.$str_checked.'
					align="absmiddle" pri="'.$price_start.'" del_pri="'.$del_price_start.'" onclick="radio_click(\'s12\');" />
					<label for="s12">Order via <strong>PayPal</strong></label>
					</li>';
				$cart_url = empty($cart_url) ? $price_one['cart_url'].$paypal_str : $cart_url;
		    }
		     if(!empty($price_one['swreg_url']))
		     {
				$str_checked = '';
				$str.= '<li show="0"  >
				<input name="s1" id="s11" type="radio" value="'.$price_one['swreg_url'].'" '.$str_checked.' pri="'.$price_start.'" del_pri="'.$del_price_start.'"  onclick="radio_click(\'s11\');" />
				<label for="s11">Order via <strong>SWREG</strong></label>
				</li>';
				$cart_url = !empty($cart_url)?$cart_url:$price_one['swreg_url'];
		    }
		}
		
		if( empty($cart_url) ) return '';
		
		$test_str = "_gaq.push(['_link', this.href]); return false;";
		$str = '<p class="price" id="pri1">'.$price_start.'<del>'.$del_price_start.'</del></p>
				<ul id="select_1" class="select_box">'.$str.'</ul>
				<p class="btn"><a onClick="'.$test_str.'" 
				href="'.$cart_url.'" id="form_a" class="add">Add to Cart</a></p>';

		$str = '<div class="col-2">
				<p><img src="http://www.iskysoft.com/images/license-benefits.png" alt="License Benefits"/></p>
				<p>
				<span class="text">Price:</span> 
				<span class="price"><s>'.$del_price_start.'</s> '.$price_start.'</span> 
				<a class="buy-now" target="_blank" href="'.$price_one['swreg_url'].'" onclick="'.$test_str.'">Buy Now</a>
				</p>
				<div class="clear"></div>
				<p class="pay"><img src="http://images.iskysoft.com/images/payments.gif" alt="Payment"/></p>
				</div>';

		unset($price_one);
		return $str;
	}


}
?>